<template>
  <j-dialog v-model="show" draggable width="90%" top="50px" title="兑付记录" :z-index="99">
    <div style="height: calc(100vh - 260px);">
      <div style="margin-top: 10px;">
        <x-form v-model="searchModel" :rules="rules" inline></x-form>
        <div style="text-align: right;margin-bottom: 10px;">
          <JButton icon="Search" type="info" @click="getList">搜索</JButton>
        </div>
      </div>
      <div>
        <j-grid :columns="fields" v-model="histList" :offset-height="100" />
      </div>
    </div>
  </j-dialog>
  <zcdflistdetail ref="detailRef"></zcdflistdetail>
</template>
<script>
import tool from "@/utils/tool";
import Zcdflistdetail from "@/views/fina/zcdflistdetail.vue";

export default {
  name: "zcdflist",
  components: { Zcdflistdetail },
  data () {
    return {
      show: false,
      rules: [
        {field: 'buId',hide: true},
        {field: 'brandId',hide: true},
        {field: 'invId',hide: true},
        {field: 'beginDate', title:'开始日期',com: 'JPicker' },
        {field: 'endDate', title:'兑付日期',com: 'JPicker' },
        {field: 'buName', title:'供应商',idField: 'buId',com: 'JAuto', cat: 'provider'},
        {field: 'brandName', title:'品牌',com: 'JAuto', cat: 'brand', idField: 'brandId'},
        {field: 'invName', title:'商品',com: 'JAuto', cat: 'goods',idField: 'invId'},
      ],
      searchModel:{
        beginDate: '',
        endDate: '',
        buId:'',
        buName: '',
        brandId: '',
        brandName:'',
        invId: '',
        invName: ''
      },
      fields:[
        {type: 'index', width: 60},
        {title: '往来单位',width: 260, field: 'buName',align: 'left'},
        {title: '兑付日期',width: 110, field: 'billDate'},
        {title: '截止日期',width: 110, field: 'endDate'},
        {title: '兑付方式',width: 110, field: 'dfType'},
        {title: '收入账户',width: 110, field: 'accName'},
        {title: '品牌',width: 90, field: 'brandName',},
        {title: '商品',width: 200, field: 'invName',align: 'left'},
        {title: '兑付金额',width: 120, field: 'amount',formatter:'formatMoney',align: 'right',sum: true},
        {title: '操作',width: 160,btns:[{label: '作废',click:(row)=>{this.waste(row)}},{label: '兑付商品明细',click:(row)=>{this.detail(row)}}]}
      ],
      histList: []
    }
  },
  methods: {
    open () {
      this.show = true
      this.getList()
    },
    getList () {
      tool.post('pay/zcdflist', {formData: this.searchModel}).then(ret => {
        this.histList = ret.data.list
      })
    },
    waste (row) {
      tool.confirm('确定要作废兑付？','作废提示').then(ret => {
        tool.post('pay/zcdfWaste', {id: row.id}).then(ret => {
          if(ret.stat) {
            this.getList()
          }
        })
      })
    },
    detail (row) {
      this.$refs.detailRef.open(row)
    }

  }
};
</script>
<style scoped lang="scss">

</style>